package com.bruce.starts.demo.thread.demo;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class ThreadDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        ThreadDemo threadDemo = new ThreadDemo();
        threadDemo.futureTest();
    }

    public void futureTest() throws ExecutionException, InterruptedException {
        ExecutorService executorService = Executors.newFixedThreadPool(1);

        TestParam testParam = new TestParam();
        Future<TestParam> future = executorService.submit(new RunnableDemo(testParam), testParam);
        System.out.println(future.get().getCode());
        System.out.println(testParam.getCode());
        executorService.shutdown();
    }


}

class RunnableDemo implements Runnable {

    private TestParam testParam;

    public RunnableDemo(TestParam testParam) {
        this.testParam = testParam;
    }

    @Override
    public void run() {
        testParam.setCode("test");
        testParam.setKey("test");
    }
}

class TestParam {
    private String key;
    private String code;

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }
}
